package com.baseweb.webadmin.core.model.mapper;

import com.baseweb.webadmin.core.model.pojo.ByChannel;
import com.baseweb.webadmin.core.model.pojo.ByChannelKeyword;
import com.baseweb.webadmin.core.model.pojo.ByChannelKeywordExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

public interface ByChannelKeywordMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    int countByExample(ByChannelKeywordExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    int deleteByExample(ByChannelKeywordExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    @Delete({
        "delete from by_channel_keyword",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    @Insert({
        "insert into by_channel_keyword (position_id, parent_id, ",
        "name, sort, descn, ",
        "status, create_time, ",
        "update_time, ",
        "url)",
        "values (#{positionId,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, ",
        "#{name,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, #{descn,jdbcType=VARCHAR}, ",
        "#{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{url,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(ByChannelKeyword record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    int insertSelective(ByChannelKeyword record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    List<ByChannelKeyword> selectByExample(ByChannelKeywordExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    @Select({
        "select",
        "id, position_id, parent_id, name, sort, descn, status, create_time, update_time, ",
        "url",
        "from by_channel_keyword",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    ByChannelKeyword selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    int updateByExampleSelective(@Param("record") ByChannelKeyword record, @Param("example") ByChannelKeywordExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    int updateByExample(@Param("record") ByChannelKeyword record, @Param("example") ByChannelKeywordExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    int updateByPrimaryKeySelective(ByChannelKeyword record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_channel_keyword
     *
     * @mbggenerated Thu May 18 00:57:58 CST 2017
     */
    @Update({
        "update by_channel_keyword",
        "set position_id = #{positionId,jdbcType=INTEGER},",
          "parent_id = #{parentId,jdbcType=INTEGER},",
          "name = #{name,jdbcType=VARCHAR},",
          "sort = #{sort,jdbcType=INTEGER},",
          "descn = #{descn,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "url = #{url,jdbcType=VARCHAR}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ByChannelKeyword record);

    @Select({
            "select",
            "id, position_id, parent_id, name, sort, descn, status, create_time, update_time, ",
            "url",
            "from by_channel_keyword ",
            "where position_id = 1002 and status = 1"
    })
    @ResultMap("BaseResultMap")
    List<ByChannelKeyword> findAllByChannelKeywordByLeftList();

    /**
     * 根据根据user关联查询关键字
     */
    @Select({
            "select",
            "id, position_id, parent_id, name, sort, descn, status, create_time, update_time, ",
            "url,uc.channel_id as type  ",
            "from by_channel_keyword ",
            "LEFT JOIN ",
            "(select user_channel.channel_id from user,user_channel where user.id = user_channel.user_id and user.username = #{0}) as uc ",
            "on by_channel_keyword.id = uc.channel_id  ",
            "where status = 1"
    })
    @ResultMap("BaseResultMap")
    List<ByChannelKeyword> findAllByChannelKeywordByUserChannel(String username);

    @Select({
            "select",
            "id, position_id, parent_id, name, sort, descn, status, create_time, update_time, ",
            "url",
            "from by_channel_keyword ",
            "where parent_id = #{0} and status=1"
    })
    @ResultMap("BaseResultMap")
    List<ByChannelKeyword> findChannelKeywordByParentId(int parentId);
}